home *** CD-ROM | disk | FTP | other *** search
- Path: news.iadfw.net!usenet
- From: Mark Nelson <markn@airmail.net>
- Newsgroups: comp.lang.c++
- Subject: Re: mutual data structures
- Date: Sat, 23 Mar 1996 15:52:50 -0600
- Organization: customer of Internet America
- Message-ID: <315472B2.2F2A@airmail.net>
- References: <4j1mu1$fas@baskerville.CS.Arizona.EDU>
- NNTP-Posting-Host: dal17-01.ppp.iadfw.net
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0GoldB2 (Win95; I)
-
- Koen De Bosschere wrote:
- >
- > I am trying to create a data structure consisting of
- > two linked lists, with nodes pointing at each other
- > between the two lists.
- >
- > The problem is that in order to create typed pointers, I
- > need the definition of the class, and no matter how I reorder
- > the class definitions, there will always be an undefined
- > class at some point.
-
- > This kind of data structure
- > cannot be so unusual, so other people must have faced
- > this problem before.
-
- You are right, it is a problem that has been dealt with. You need
- a simple forward declaration to inform the compiler of the existence
- of the class:
-
- class node1;
-
- class node2 {
- node1 *n1;
- };
-
- class node1 {
- node2 *n2;
- };
-
- The incomplete definition of node1 gives the compiler enough information
- to create a pointer, which is all you need at that point.
-
- Mark Nelson
- http://web2.airmail.net/markn
-